package edu.rit.drh4818.raytracing.shaders.procedural;

import java.awt.Color;

import edu.rit.drh4818.raytracing.shaders.Shader;
import edu.rit.drh4818.raytracing.util.Intersection;

/**
 * @author Darren Headrick
 *
 */
public class TiledShader implements Shader 
{
	private Color color1, color2;
	private double width, depth, width_half, depth_half;
	
	public TiledShader( Color color1, Color color2, double width, double depth )
	{
		this.color1 = color1;
		this.color2 = color2;
		this.depth = depth;
		depth_half =  depth/2;
		this.width = width;
		width_half = width/2;
	}
	
	public Color getColor(Intersection in, int d) 
	{
		double value = (int)in.getX() % width;
		boolean color1 =  value > width_half || value <= 0 && value > -width_half;
		value = (int)in.getZ() % depth;
		
		if( !( value > depth_half || value <= 0 && value > -depth_half) )
		{
			color1 = !color1;
		}
		
		return (color1)?this.color1:this.color2;
		
	}
}
